#include <stdlib.h> // Pour calloc()
#include "entier.h"
char* itoc(unsigned int integer)
{
    int d = integer, r, i=0;
    int nbChar = nbChiffre(integer);
    char *string = calloc(nbChar+1, sizeof(char));
    for(i=nbChar-1; i>=0; i--) {
        r = d%10;
        d /= 10;
        if(r || d)
            string[i] = '0'+r;
    }
    return string;
}

unsigned int nbChiffre(unsigned int integer)
{
    int d = integer, r, i=0;
    //int intBitsSize = sizeof(unsigned int)*8;
    do {
        r = d%10;
        d /= 10;
        i++;
    } while(d || r);
    return i-1;
}

unsigned int btoi(char bin)
{
    int integer = 0, i;
    int charBitsSize = sizeof(char)*8;
    for(i=0; i<charBitsSize; i++)
        integer += bin&(0x01<<i);
    return integer;
}

char* btoc(char bin)
{
    int i;
    int charBitsSize = sizeof(char)*8;
    char *string = calloc(charBitsSize+1, sizeof(char));
    for(i=0; i<charBitsSize; i++)
        string[i] = bin&(0x01<<(charBitsSize-i-1)) ? 0x31 : 0x30; /* retabli l'ordre et place des 1 à chaque correspondance */
    return string;
}

